const fse = require('fs-extra');
const axios = require('axios');

const webhook =  'https://open.feishu.cn/open-apis/bot/v2/hook/f1832170-98b2-4471-9b05-4f41f2a505c5';
/**
 * 遍历文件夹
 * @param {string} filePath 
 * @param {function} fn 
 * @returns 
 */
function recursionFilePath(filePath, fn) {
    if (fse.statSync(filePath).isDirectory()) {
        fse.readdirSync(filePath).forEach((file) => {
            recursionFilePath(`${filePath}/${file}`, fn);
        });
        return;
    }

    fn(filePath);
}

const preMoveResPaths = [
    "../assets/resources/gl_zh/login",
    "../assets/resources/gl_zh/startmini",
    "../assets/resources/gl_zh/uiloading",
    "../assets/resources/gl_zh/userAgreement",
    "../assets/resources/gl_zh/res/spine",
]

const sendWebhook = async (text) => {
  const params = {
    msg_type: 'text',
    content: {
      text
    }
  };
  const { data: result } = await axios.post(
    webhook,
    params
  );
  return console.log(result);
};


exports.preMoveResPaths = preMoveResPaths;
exports.recursionFilePath = recursionFilePath;
exports.sendWebhook = sendWebhook;
